﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrightIdeasSoftware;
using Managistics.Warehouse.Views.Libs.NNGrid.Datas;
using Managistics.Warehouse.Views.Libs.NNGrid.Columns;
using System.Windows.Forms;

namespace Managistics.Warehouse.Views.Libs.NNGrid.Controls
{
    public class NNAutoComplete : TextBox
    {
        private object sender;
        private CellEditEventArgs cell;

        public NNAutoComplete()
        {
            
        }

        public NNAutoComplete(object sender, CellEditEventArgs cell)
        {
            this.Sender = sender;
            this.Cell = cell;
        }

        public object Sender
        {
            get { return sender; }
            set { this.sender = value; }
        }

        public CellEditEventArgs Cell
        {
            get { return cell; }
            set { cell = value; }
        }
        
        public void Initialize()
        {

            NNControlRender dataRender = ((NNGridColumn)(this.Cell.Column)).ControlRender;

            this.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            this.AutoCompleteSource = AutoCompleteSource.CustomSource;
            AutoCompleteStringCollection auto = new AutoCompleteStringCollection();

            auto.AddRange((string[])dataRender.DataSource);
            this.AutoCompleteCustomSource = auto;
            this.Text = this.Cell.Value.ToString();
        }

        public object DataResponse()
        {
            TextBox tb = (TextBox)Cell.Control;
            return tb.Text;
        }

    }
}
